package com.msite.service

import com.msite.mapper.SysMenuMapper
import com.msite.model.SysMenu
import org.springframework.stereotype.Component

import javax.annotation.Resource
/**
 * Created by tpeng on 2015/12/3.
 */
@Component
class SysMenuService {

    @Resource
    SysMenuMapper sysMenuMapper;

    /**
     * 根据{管理员userId}，获取该用户的菜单数据
     * @param userId
     * @return
     */
    Map<String, List<SysMenu>> selectMenuMapByUserId(Long userId){
        def mlist = sysMenuMapper.selectSysMenuByUserId(userId, null)
        def key
        mlist.inject([:]) {
            map,item ->
                key = (item.pid as String)
                def plist = map[key] ? map[key] : []
                plist << item
                map << [(key) : plist]
        }
    }


}
